/**
Company: Sarkar software technologys
WebSite: http://www.sarkar.cn
Author: yeganaaa
Date : 6/2/18
Time: 12:00 AM
 */

package Cn.Sarkar.MMS.LayerOne

import Cn.Sarkar.Entities.MMS.ToJsonEntities.JCompany
import Cn.Sarkar.Entities.MMS.ToJsonEntities.JContacts
import Cn.Sarkar.Entities.MMS.ToJsonEntities.JCountry
import Cn.Sarkar.Entities.MMS.ToJsonEntities.JMemberShipLevel
import Cn.Sarkar.Entities.ToJsonEntities.JDescription
import Cn.Sarkar.Entities.ToJsonEntities.JName
import Cn.Sarkar.EntityDream.CoreEngine.RDBMS.IDataContext
import Cn.Sarkar.MMS.Entities.Additional.Contact
import Cn.Sarkar.MMS.Entities.Additional.Country
import Cn.Sarkar.MMS.Entities.Additional.Description
import Cn.Sarkar.MMS.Entities.Additional.Name
import Cn.Sarkar.MMS.Entities.Independent.Company
import Cn.Sarkar.MMS.Entities.Independent.Wallet.MemberShipLevel

fun JName.convertToDbEntity(db: IDataContext): Name {
    val retv = Name(db)
    retv.ug = this.ug
    retv.zh = this.zh
    retv.en = this.en
    retv.kz = this.kz
    retv.ru = this.ru
    retv.category = this.category
    return retv
}

fun JDescription.convertToDbEntity(db: IDataContext): Description {
    val retv = Description(db)
    retv.ug = this.ug
    retv.zh = this.zh
    retv.en = this.en
    retv.kz = this.kz
    retv.ru = this.ru
    retv.category = this.category
    return retv
}

fun JMemberShipLevel.convertToDbEntity(db: IDataContext): MemberShipLevel {
    val retv = MemberShipLevel(db)
    retv.name = (this.name as JName).convertToDbEntity(db)
    retv.description = (this.description as JDescription).convertToDbEntity(db)
    return retv
}

fun JCountry.convertToDbEntity(db: IDataContext): Country{
    val retv = Country(db)

    retv.name = (this.name as JName).convertToDbEntity(db)
    retv.parentID = this.parentId
    retv.latitude = this.latitude
    retv.longitude = this.longitude
    retv.layer = this.layer

    return retv
}

fun JContacts.convertToDbEntity(db: IDataContext): Contact{
    val retv = Contact(db)
    retv.phoneNumber = this.phoneNumber
    retv.eMail = this.eMail
    retv.qqNumber = this.qqNumber
    retv.weChatNumber = this.weChatNumber
    return retv
}

//fun JCompany.convertToDbEntity(db: IDataContext): Company{
//    val retv = Company(db)
//    val _name = (this.name as JName).convertToDbEntity(db).apply { id = -1 }
//    retv.name = _name
//    retv.description = (this.description as JDescription).convertToDbEntity(db).apply { id = -1 }
//    retv.addr = (this.addr as JCountry).convertToDbEntity(db)
//    retv.contacts = (this.contacts as JContacts).convertToDbEntity(db)
//    return retv
//}